package com.beimihu.leetcode.基本算法;

public class maopao {
    public static void sort(int[] arr){
        boolean flag = false;
        for(int i = 0 ; i < arr.length - 1 ;i++){
            for (int j = 0 ; j < arr.length - 1 - i ; j++){
                if(arr[j] > arr[j + 1]){
                    flag = true;
                    int temp = arr[j ];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }
            }
            if(!flag){
                break;
            }
            else{
                flag = false;
            }
        }
    }

    public static void main(String[] args) {
        int[] arr = {64, 34, 25, 12, 22, 11, 90};
        System.out.println("排序前的数组:");
        for (int num : arr) {
            System.out.print(num + " ");
        }

        sort(arr);

        System.out.println("\n排序后的数组:");
        for (int num : arr) {
            System.out.print(num + " ");
        }
    }
}
